package com.khyr.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.khyr.Vo.SearchSalesListCountVo;
import com.khyr.Vo.SearchSalesListVo;
import com.khyr.Vo.GetCheckOrderDetailsByItemIdVo;
import com.khyr.Vo.SelectSysCheckItemVo;
import com.khyr.entity.*;
import com.khyr.feign.UserFeign;
import com.khyr.service.InspectionItemStatisticsService;
import com.khyr.vo.R;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：Zhang
 * @date ：Created in 2025/3/12 10:24
 * @description：检查项目统计
 * @modified By：
 * @version: 1.0
 */
@RestController
@RequestMapping("/accountant/InspectionItemStatistics")
public class InspectionItemStatisticsController {
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private UserFeign userFeign;
    @Autowired
    private InspectionItemStatisticsService inspectionItemStatisticsService;

    /**
     * @create by: Zr
     * @description: 获取所有的检查项目
     * @create time: 2025/3/12 11:22
     * @param
     * @return com.khyr.vo.R<java.util.List<com.khyr.entity.SysCheckItem>>
     */
    @PostMapping("/selectSysCheckItem")
    public R<List<SysCheckItem>> selectSysCheckItem()
    {
        return inspectionItemStatisticsService.selectSysCheckItem();
    }
    @PostMapping("/selectSysCheckItemByKeyWords")
    public R<Page<SysCheckItem>> selectSysCheckItemByKeyWords(@RequestBody SelectSysCheckItemVo data)
    {
        return inspectionItemStatisticsService.selectSysCheckItemByKeyWords(data);
    }
    /**
     * @create by: Zr
     * @description: 获取已售出的项目
     * @create time: 2025/3/12 11:42
     * @param data
     * @return com.khyr.vo.R<java.util.List<com.khyr.entity.SysCheckItem>>
     */
    @PostMapping("/searchSalesList")
    public R<List<HisCheckResult>> searchSalesList(@RequestBody SearchSalesListVo data)
    {
        return inspectionItemStatisticsService.searchSalesList(data);
    }
    /**
     * @create by: Zr
     * @description: 检查项目统计列表；通过检查项目名称日期查询检查项目列表，若无输入日期则默认查询当天
     * @create time: 2025/3/19 14:11
     * @param data
     * @return com.khyr.vo.R<java.util.List<com.khyr.Vo.SearchSalesListCountVo>>
     */
    @PostMapping("/selectSysCheckItemCount")
    public R<List<SearchSalesListCountVo>> searchSalesListCount(@RequestBody SearchSalesListVo data)
    {
        return inspectionItemStatisticsService.searchSalesListCount(data);
    }
    /**
     * @create by: Zr
     * @description: 查询当前患者的检查处方的详情
     * @create time: 2025/3/19 14:16
     * @param coType
     * @return com.khyr.vo.R<java.util.List<com.khyr.entity.CareOrder>>
     */
    @GetMapping("/getCareOrderListByCoType")
    public R<List<CareOrder>> getCareOrderListByCoType(String coType)
    {
        String token = request.getHeader("token");
        // 获取当前登录者的信息
        HisPatient patient=userFeign.getPatientInfo(token).getData();
        return inspectionItemStatisticsService.getCareOrderListByCoType(coType,patient);
    }
    /**
     * @create by: Zr
     * @description: 根据开诊明细id(item_id) 查询处方明细(CareOrderItem)和检查结果(HisCheckResult)
     * @create time: 2025/3/19 15:10
     * @param itemId
     * @return com.khyr.vo.R<com.khyr.Vo.GetCheckOrderDetailsByItemIdVo>
     */
    @GetMapping("/getCheckOrderDetailsByItemId/{itemId}")
    private R<GetCheckOrderDetailsByItemIdVo> getCheckOrderDetailsByItemId(@PathVariable String itemId)
    {
        return inspectionItemStatisticsService.getCheckOrderDetailsByItemId(itemId);
    }

}
